package com.cloudfun.campusshare.service.handler;

import com.cloudfun.campusshare.common.constant.DelayMsgType;
import com.cloudfun.campusshare.common.constant.RoleType;
import com.cloudfun.campusshare.common.security.AuthenticationHolder;
import com.cloudfun.campusshare.common.security.UserAuthentication;
import com.cloudfun.campusshare.sender.DelayMessage;
import com.google.common.collect.Sets;

import java.util.Arrays;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/6/18 19:43
 * @description :
 */
public interface DelayMessageHandler {

    DelayMsgType support();

    void handleMessage(DelayMessage message);

    default void prepareUserContext(DelayMessage message) {
        AuthenticationHolder.setUserAuth(new UserAuthentication(message.getUserId(), "", Sets.newHashSet(Arrays.asList(RoleType.CUSTOMER.name()))));
    }

    default void destroyUserContext() {
        AuthenticationHolder.clear();
    }
}
